<html><head><title>Normalize populations</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="Rchm.css">
</head>
<body>

<table width="100%"><tr><td>normPop(LGS)</td><td align="right">R Documentation</td></tr></table><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
<param name="keyword" value="R:   normPop">
<param name="keyword" value=" Normalize populations">
</object>


<h2>Normalize populations</h2>


<h3>Description</h3>

<p>
<code>normPop</code> takes a list of populations or a list of haplotype counts and adjusts the proportion of each population to a specified one. The frequency of each haplotype within populations remains unchanged.
</p>


<h3>Usage</h3>

<pre>
normPop(hapList= NULL, proportions= NULL, popSize= 1, onePop= TRUE)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>hapList</code></td>
<td>
A list of population matrices or a list of vectors of haplotype counts. </td></tr>
<tr valign="top"><td><code>proportions</code></td>
<td>
A vector of proportions of the same length as <code>hapList</code>. </td></tr>
<tr valign="top"><td><code>popSize</code></td>
<td>
Final number of total individuals. </td></tr>
<tr valign="top"><td><code>onePop</code></td>
<td>
Should the populations be merged into a single one? </td></tr>
</table>

<h3>Details</h3>

<p>
Use <code><a onclick="findlink('base', 'list.html')" style="text-decoration: underline; color: blue; cursor: hand">list</a></code> to return <code>hapList</code> as a list of matrices or vectors.
</p>
<p>
<code>proportions</code> does not have to sum up to one. The default vector of proportions will make each population equally represented.
</p>
<p>
<code>popSize</code> defaults to 1 although this is not biologically meaningful. However, in most cases what matters is the relative amount of each haplotype rather than its absolute number
</p>


<h3>Value</h3>

<p>
If <code>onePop=FALSE</code>, <code>normPop</code> will return a list of matrices and/or vectors if <code>hapList</code> is a list of matrices and/or vectors.
<br>
If <code>onePop=TRUE</code>, <code>normPop</code> will return a single matrix (or single vector) with number of rows equal to the number of haplotypes in <code>hapList</code> and column of counts adjusted according to <code>proportions</code>.
<br>
If <code>hapList</code> contains both matrices and vectors, <code>onePop</code> will be ignored and the value returned will be a list.</p>

<h3>Author(s)</h3>

<p>
Dario Beraldi &lt;<a href="mailto:dario.beraldi@ed.ac.uk">dario.beraldi@ed.ac.uk</a>&gt;
</p>


<h3>Examples</h3>

<pre>
# Two populations wih different number of haplotype counts
(pop1&lt;- cbind(matrix(data=0, nrow=5, ncol=10), nclones=1:5))
(pop2&lt;- cbind(matrix(data=1, nrow=5, ncol=10), nclones=10:14))

# Normalize to have each population equally represented (500 individuals each)
(n1&lt;- normPop(list(pop1, pop2), onePop=FALSE, proportions=c(1,1), popSize=1000))
sum(n1[[1]][,11])
sum(n1[[2]][,11])

data(pcMap)
pop1&lt;- cbind(matrix(data=0, nrow=10, ncol=80), nclones=1)
pop2&lt;- cbind(matrix(data=1, nrow=10, ncol=80), nclones=1)

# Effect of varying proportions on LGS profiles
n11&lt;- normPop(list(pop1, pop2), onePop=FALSE, proportions=c(1,1))
n51&lt;- normPop(list(pop1, pop2), onePop=FALSE, proportions=c(5,1))
n201&lt;- normPop(list(pop1, pop2), onePop=FALSE, proportions=c(20,1))

lgs11&lt;- simLGS(offspring=100, NoP1=n11[[1]], NoP2=n11[[2]], 
       scenario="EqualFitness99", map=pcMap, gen.dist="phy")
lgs51&lt;- simLGS(offspring=100, NoP1=n51[[1]], NoP2=n51[[2]], 
       scenario="EqualFitness99", map=pcMap, gen.dist="phy")
lgs201&lt;- simLGS(offspring=100, NoP1=n201[[1]], NoP2=n201[[2]], 
       scenario="EqualFitness99", map=pcMap, gen.dist="phy")

plotLGS(lgs11, show.range=FALSE)
plotLGS(lgs51, add=TRUE, col="blue")
plotLGS(lgs201, add=TRUE, col="red")
legend("topleft", horiz=TRUE, legend=c("1:1", "5:1", "20:1"), 
        col=c("black", "blue", "red"), lty="solid", bg="white", pch=21, cex=0.85)

# Varying proportions in backcrosses
# First generation
lgsG1&lt;- simLGS(offspring=100, scenario="EqualFitness99", map=pcMap, gen.dist="phy")
plotLGS(lgsG1, show.range=FALSE)

# Prepare backcross
pop1&lt;- cbind(matrix(data=0, nrow=10, ncol=80), nclones=1)
popBC&lt;- normPop(list(lgsG1$selPop, pop1), onePop=FALSE, proportions=c(1,2))
lgsBC1&lt;- simLGS(offspring=100, NoP1=popBC[[1]], , NoP2=popBC[[2]], scenario="EqualFitness99", map=pcMap, gen.dist="phy")
plotLGS(lgsBC1, add=TRUE, col="blue")
</pre>

<script Language="JScript">
function findlink(pkg, fn) {
var Y, link;
Y = location.href.lastIndexOf("\\") + 1;
link = location.href.substring(0, Y);
link = link + "../../" + pkg + "/chtml/" + pkg + ".chm::/" + fn;
location.href = link;
}
</script>


<hr><div align="center">[Package <em>LGS</em> version 0.9 <a href="00Index.html">Index]</a></div>

</body></html>
